package com.cn.kabalifemerchants.ui.user.activity;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.cn.kabalifemerchants.R;
import com.cn.kabalifemerchants.base.BasePresenter;
import com.cn.kabalifemerchants.base.IBaseActivity;
import com.cn.kabalifemerchants.base.MyApplication;
import com.cn.kabalifemerchants.config.LoginHelper;
import com.cn.kabalifemerchants.ui.login.AgreementActivity;
import com.cn.kabalifemerchants.ui.user.bean.AppVersionBean;
import com.cn.kabalifemerchants.utils.RxToast;
import com.flyco.roundview.RoundTextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by 晓林 on 2020/10/20.
 * function: 通用设置
 */
public class SystemSetActivity extends IBaseActivity<SystemSetView, SystemSetPresenter> implements SystemSetView {
    @BindView(R.id.tv_edition)
    TextView tvEdition;
    @BindView(R.id.tv_msg)
    RoundTextView tvMsg;
    @BindView(R.id.tv_phone)
            TextView tvPhone;
    AppVersionBean appVersionBean;


    @Override
    protected SystemSetPresenter createPresenter() {
        return new SystemSetPresenter();
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_sys_set;
    }


    @OnClick({R.id.ll_btn_phone,R.id.ll_btn_edition, R.id.ll_btn_help, R.id.ll_btn_about_us, R.id.ll_btn_opinion, R.id.ll_btn_privacy})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_btn_phone:
                    Intent intent = new Intent(Intent.ACTION_DIAL);
                    Uri data = Uri.parse("tel:" + tvPhone.getText().toString().trim());
                    intent.setData(data);
                    startActivity(intent);
                break;
            case R.id.ll_btn_edition:
                if (appVersionBean != null) {
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("appVersionBean", appVersionBean);
                    $startActivity(EditionActivity.class, bundle);
                }

                break;
            case R.id.ll_btn_help:
                //todo 帮助
                $startActivity(HelpListActivity.class);
                break;
            case R.id.ll_btn_about_us:
                $startActivity(AboutUsActivity.class);
                break;
            case R.id.ll_btn_opinion:
                //todo 意见
                $startActivity(OpinionActivity.class);
                break;
            case R.id.ll_btn_privacy:
                Bundle bundle = new Bundle();
                bundle.putInt("sign", 2);
                $startActivity(AgreementActivity.class, bundle);
                break;
        }
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);
        setTitleBar("通用配置");
        tvEdition.setText("v " + MyApplication.getVersionName());
        mPresenter.onAppVersionData(LoginHelper.getLonginData().getResult());
    }

    @Override
    public void onReLoggedIn(String msg) {
        RxToast.error(msg);
        LoginHelper.againGoToLoginActivity(getMe());
    }

    @Override
    public void onError(String msg) {
        RxToast.error(msg);
    }

    @Override
    public Context _getContext() {
        return getMe();
    }

    @Override
    public void onAppVersionSuccess(AppVersionBean bean) {
        appVersionBean = bean;
        if (MyApplication.getVersionName().equals(bean.getResult().getVersion())) {
            tvMsg.setVisibility(View.GONE);
        } else tvMsg.setVisibility(View.VISIBLE);
    }
}
